from pydiigo import DiigoApi
from datetime import datetime

from . import DeliciousLinks
from . import Link

class DiigoQuery:
    def __init__(self, login):
        self.login = login
    
    def get_links(self, tags, start_date=None, end_date=None):
        result = DeliciousLinks.DeliciousLinks()
        
        api = DiigoApi(user=self.login.login, password=self.login.password)
        bookmarks = api.bookmarks_find(users='maxim75', tags=tags, rows=5000)

        for bookmark in bookmarks:
            created_date = datetime.strptime(bookmark.created_at, "%Y/%m/%d %H:%M:%S +0000")
            result.append(Link.Link(bookmark.url, bookmark.tags.split(","), 
                bookmark.title, bookmark.desc, created_date)) 
   
        return result
